#include "mytimer.h"
#include "QTime"
MyTimer::MyTimer(QString info)
{
    timer = new QTimer();
    this->info = info + " ";
    connect(timer,&QTimer::timeout,this,&MyTimer::showtime);
}

void MyTimer::showtime(){
    sec++;
    setText(info + cal_time(sec));
}
QString MyTimer::cal_time(long sec){
    int minitue = sec/60,second = sec - minitue*60;
    QString s;
    if(minitue < 10) s += ("0"+ QString::number(minitue));
    else s += QString::number(minitue);
    s += ":";
    if(second < 10) s += ("0"+ QString::number(second));
    else s += QString::number(second);
    return s;
}

void MyTimer::pause(){
    timer->stop();
}

void MyTimer::reset(){
    sec = 0;
    timer->stop();
    setText(info + "00:00");
}

void MyTimer::start(){
    timer->start(1000);
}

void MyTimer::restart(){
    sec = 0;
    timer->start(1000);
}
